package com.sk.weichat.util.skin.setter;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;

/**
 * @author lzs
 * @date 2019/9/18
 * Email:343067508@qq.com
 **/
public class ImageViewSrcSetter  extends ViewSetter {
    public ImageViewSrcSetter(View targetView, int resId) {
        super(targetView, resId);
    }

    @Override
    public void setValue(Resources.Theme newTheme, int themeId) {
        if(mView!=null){
            TypedArray a = newTheme.obtainStyledAttributes(themeId,
                    new int[] { mAttrResId });
            int attributeResourceId = a.getResourceId(0, 0);
            Drawable drawable = mView.getResources().getDrawable(
                    attributeResourceId);
            a.recycle();
            ((ImageView)mView).setImageDrawable(drawable);
        }
    }
}
